package pro1.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import pro1.model.User;

public interface UserMapper {
	int deleteByPrimaryKey(Integer id);

	int insert(User record);

	int insertSelective(User record);

	User selectByPrimaryKey(Integer id);

	int updateByPrimaryKeySelective(User record);

	int updateByPrimaryKey(User record);

	@Select("select id, username, password, role, createtime, elsestring1, elsestring2, elsestring3, "
			+ "elseint1, elseint2 from user where username=#{userName}")
	User selectByUserName(@Param("userName") String userName);

	List<Map<String, Object>> selectAll(@Param("userName") String userName, @Param("name") String name,
			@Param("sex") Integer sex, @Param("dep") Integer dep, @Param("page") Integer page,
			@Param("num") Integer num);

	@Select("select COALESCE(count(id),0) from user where username=#{userName}")
	int selectNumByUserName(@Param("userName") String userName);

	@Select("select u.id, u.username, u.createtime, u.elsestring1, u.elsestring2, u.elsestring3, u.elseint1, "
			+ "u.elseint2, c.id as characterid, c.name as charatername from user as u left join "
			+ "admin_character as a on u.id=a.id left join javaweb.`character` as c on a.characterid=c.id"
			+ " where u.role=1 order by u.createtime desc")
	List<Map<String, Object>> selectAllAdmin();

	@Select("select COALESCE(id,0) from user order by id desc limit 1")
	int selectMaxId();

}